package pro.cherish.knowledgecmomon.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import pro.cherish.knowledgecmomon.entity.BaseException;
import pro.cherish.knowledgecmomon.enums.IErrorCode;

/**
 * @author 创建人：cherish
 * @version 版本号：V1.0
 * <p>
 * ***************************修订记录************************************
 * 2019-11-02 cherish 创建该类功能。
 * **********************************************************************
 * </p>
 * @ClassName 类名：BasicError
 * @Description 功能说明：
 * <p>
 * TODO
 * </p>
 * **********************************************************************
 * @date 创建日期： 2019-11-02 cherish
 */
@AllArgsConstructor
public enum BasicError implements IErrorCode {
    CHECK_FAIL("1001001", "参数校验失败[%s]%s"),
    CHECK_PARAMS_VALID("1001001", "%S"),
    CHECK_NOT_READABLE("1001002", "参数无效或格式异常"),
    CHECK_NOT_HANDLER("101004", "非法访问"),
    NOTIFY_MERCHANT_FAIL("101005", "通知平台商户失败"),

    NOT_PERMISSION("101009", "无此访问权限"),

    SESSION_TIMEOUT("1002004", "会话过期，请重新登录！"),
    // NO_LOGIN("1002000","未登录!"),seeison丢失，请重新登录
    // SESSION_TIME_OUT("1002004","会话过期，请重新登录!"),
    NO_LOGIN("1002000", "未登录!"),
    VAPTCHA_CODE_ERROR("1002001", "验证码错误!"),
    OPERATOR_CODE_OR_PWD_ERROR("1002002", "账号或者密码错误"),
    OPERATOR_STATUS_ERROR("1002003", "账号状态异常"),
    TIME_OUT("1008999", "请求超时"),
    SQL_ERROR("1008998", "系统异常"),
    SYS_ERROR("1008999", "系统异常[%s]"),

    // 字典项1011
    DICT_CODE_IS_EXIST("1011001", "字典编码已存在"),
    DICT_SQL_INSERT_ERROR("1011002", "字典插入错误"),
    DICT_SQL_UPDATE_ERROR("1011003", "字典更新错误"),
    DICT_SQL_DELETE_ERROR("1011004", "字典删除错误"),
    DICT_IS_NOTEXIST("1011006", "字典不存在"),

    DICTITEM_CODE_IS_EXIST("1012001", "字典项编码已存在"),
    DICTITEM_SQL_INSERT_ERROR("1012002", "字典项插入错误"),
    DICTITEM_SQL_UPDATE_ERROR("1012003", "字典项更新错误"),
    DICTITEM_SQL_DELETE_ERROR("1012004", "字典项删除错误"),
    DICTITEM_IS_NOTEXIST("1012006", "字典项不存在"),
    DICTITEM_PARENT_IS_NOTEXIST("1012006", "父类字典项不存在"),

    CONFIG_CODE_IS_EXIST("1013001", "配置信息编码编码已存在"),
    CONFIG_SQL_INSERT_ERROR("1013002", "配置信息插入错误"),
    CONFIG_SQL_UPDATE_ERROR("1013003", "配置信息更新错误"),
    CONFIG_SQL_DELETE_ERROR("1013004", "配置信息删除错误"),
    CONFIG_IS_NOTEXIST("1013006", "配置信息不存在");
    @Getter
    private final String code;
    @Getter
    private final String msg;

    public BaseException toException(Object... args) {
        return new BaseException(this.code, String.format(msg, args));
    }


    public BaseException toException(Throwable e, Object... args) {
        return new BaseException(this.code, String.format(msg, args), e);
    }

    public BaseException toException() {
        return new BaseException(this.code, msg);
    }

    public BaseException toException(Throwable e) {
        return new BaseException(this.code, msg, e);
    }
}
